# import requests
from curl_cffi import requests
import os
import shutil
if os.path.exists('static/时光图源'):
    shutil.rmtree('static/时光图源')
os.mkdir('static/时光图源')
headers = {
    'Accept': '*/*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Origin': 'https://snake.timeline.ink',
    'Pragma': 'no-cache',
    'Referer': 'https://snake.timeline.ink/latest',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'cross-site',
    'Timeline-Client': 'timelineweb',
    'Timeline-Device': '20fc4fca80d07b86a0c99059d71ad39f',
    'Timeline-Pwd': '',
    'Timeline-User': '',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Chromium";v="140", "Not=A?Brand";v="24", "Google Chrome";v="140"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

params = {
    'order': 'date',
    'seed': '1761826956977',
    'no': '47738',
    'id': '',
}

response = requests.get('https://api.nguaduot.cn/snake/v4?order=date&seed=1761830787522&no=99999999&id=', params=params, headers=headers)
data_info = response.json()['data']
for data in data_info:
    copyright = data['copyright']
    imgurl = data['imgurl']
    thumburl = data['thumburl']
    cookies = {
        'fid': '464',
        'xxtenc': 'b4ae1f0d560dd36e194489a9f5905f87',
    }
    
    headers = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        'Cache-Control': 'no-cache',
        'Connection': 'keep-alive',
        'Pragma': 'no-cache',
        'Sec-Fetch-Dest': 'document',
        'Sec-Fetch-Mode': 'navigate',
        'Sec-Fetch-Site': 'none',
        'Sec-Fetch-User': '?1',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
        'sec-ch-ua': '"Chromium";v="140", "Not=A?Brand";v="24", "Google Chrome";v="140"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        # 'Cookie': 'fid=464; xxtenc=b4ae1f0d560dd36e194489a9f5905f87',
    }
    res = requests.get(thumburl, headers=headers,cookies= cookies,params=params)
    print(res.status_code)
    with open(f'static/时光图源/{copyright}.jpg', 'wb') as f:
        f.write(res.content)
    
    # print({'copyright': copyright, 'imgurl': imgurl, 'thumburl': thumburl})